# 作者：一只牛吗
# 2025 年01月 27日 03时 53分 12秒
# 1278599690@qq.com
class HouseItem:
    def __init__(self, name, area):
        self.name = name
        self.area = area

    def __str__(self):
        return f"{self.name} (占地面积：{self.area}平方米)"


class House:
    def __init__(self, house_type, area):
        self.house_type = house_type
        self.area = area
        self.free_area = area
        self.items_list = []

    def add_item(self, item: HouseItem): # 这里的类型注解是Python3.5+的新特性
        if item.area > self.free_area:
            print("房间已满！")
            return
        self.free_area -= item.area
        self.items_list.append(item.name)

    def remove_item(self, item):
        self.items_list.remove(item)
        self.free_area += item.area
        self.items_list.pop(item.name)

    def __str__(self):
        return f"{self.house_type} (占地面积：{self.area}平方米, 剩余空间：{self.free_area}平方米)\n" + "\n".join(self.items_list)

if __name__ == '__main__':
    bed = HouseItem("席梦思", 4)
    chest = HouseItem("衣柜", 2)
    table = HouseItem("餐桌", 1.5)
    chair = HouseItem("椅子", 1)
    # print(bed)
    # print(chest)
    # print(table)
    # print(chair)
    my_house = House("两室一厅", 30)
    my_house.add_item(bed)
    my_house.add_item(chest)
    my_house.add_item(table)
    my_house.add_item(chair)
    print(my_house)